<?php

class text_to_image_converter
{
  static public function convert_symbol_to_image($symbol)
  {
    return "<img src=\"images/symbols/$symbol.jpg\" alt=\"$symbol\" height=\"14px\">";
  }

  static public function convert_manacost_to_symbol($manacost)
  {
    $symbols = explode("|", $manacost);
    $manacost = "";
    if($symbols[0] === "")
    {
      return $manacost;
    }

    foreach($symbols as $symbol)
    {
      $manacost .= text_to_image_converter::convert_symbol_to_image($symbol);
    }

    return $manacost;
  }

  static function convert_cardtext_to_symbol($cardtext)
  {
    preg_match_all("/{(.+?)}/", $cardtext, $matches);
    if(!empty($matches[0]))
    {
      foreach($matches[0] as $key => $match)
      {
        $cardtext = str_replace($match, text_to_image_converter::convert_symbol_to_image($matches[1][$key]), $cardtext);
      }
    }

    return $cardtext;
  }
}

?>
